using Com.ContentRendering.Api.DataEngine.Handler.Self;
using Com.ContentRendering.Api.DataEngine.Handler.Child;
using System.Collections.Generic;

namespace Com.ContentRendering.Api.DataEngine
{
    /// <summary/>
    public static class ChildReflection
    {
        /// <summary/>
        public static object Translate(
            ReflectionCache reflectionCache,
            object input,
            string name)
        {
            // create the invokers
            NullChildHandler nullChild = new NullChildHandler(reflectionCache, input, name);
            CachedPropertyChildHandler cachedPropertyChild = new CachedPropertyChildHandler(reflectionCache, input, name);
            PropertyChildHandler propertyChild = new PropertyChildHandler(reflectionCache, input, name);
            CachedIndexerChildHandler cachedIndexerChild = new CachedIndexerChildHandler(reflectionCache, input, name);
            IndexerChildHandler indexerChild = new IndexerChildHandler(reflectionCache, input, name);
            DefaultChildHandler defaultChild = new DefaultChildHandler(reflectionCache, input, name);

            // create the chain
            nullChild.Successor = cachedPropertyChild;
            cachedPropertyChild.Successor = propertyChild;
            propertyChild.Successor = cachedIndexerChild;
            cachedIndexerChild.Successor = indexerChild;
            indexerChild.Successor = defaultChild;

            // fetch the results
            return nullChild.Invoke();
        }
    }
}
